﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Temp.Controller;
using Temp.Model;

namespace Temp.NLG
{
    class TemplateDecoder
    {

        public String getMessage(String template, Ontology ont)
        {
            LexiconController lCtr = new LexiconController();
            String str = template, concept = "";

            if (template.Contains("<article> <concept1>") || template.Contains("<article> <concept2>"))
            {
                if (ont.relation == "isA")
                {
                    if (ont.concept1[0] == 'a' || ont.concept1[0] == 'e' || ont.concept1[0] == 'i' || ont.concept1[0] == 'o' || ont.concept1[0] == 'u')
                        str = str.Replace("<article>", "an");
                    else
                        str = str.Replace("<article>", "a");
                }
                else
                    str = str.Replace("<article>", "");
            }
            if (template.Contains("<concept1>"))
            {
                concept = lCtr.getSynonym(ont.concept1, "Lexicon_Concept");
                if (ont.relation != "isA")
                    str = str.Replace("<concept1>", concept[0].ToString().ToUpper() + concept.Remove(0, 1));
                else
                    str = str.Replace("<concept1>", concept);
            }
            if (template.Contains("<concept2>"))
            {
                concept = lCtr.getSynonym(ont.concept2, "Lexicon_Concept");
                if (concept.Equals(""))
                    concept = ont.concept2;
                str = str.Replace("<concept2>", concept);

            }
            if (template.Contains("<relation>"))
                str = str.Replace("<relation>", lCtr.getSynonym(ont.relation, "Lexicon_Relation"));

            str = str[0].ToString().ToUpper() + str.Remove(0, 1);

            return str;
        }


    }
}
